package com.zhaoxi.project.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhaoxi.framework.aspectj.lang.annotation.Log;
import com.zhaoxi.framework.aspectj.lang.enums.BusinessType;
import com.zhaoxi.project.mes.domain.MesBom;
import com.zhaoxi.project.mes.service.impl.MesBomServiceImpl;
import com.zhaoxi.framework.web.controller.BaseController;
import com.zhaoxi.framework.web.domain.AjaxResult;
import com.zhaoxi.common.utils.poi.ExcelUtil;
import com.zhaoxi.framework.web.page.TableDataInfo;

/**
 * 生产物品Controller
 * 
 * @author zhaoxi
 * @date 2023-08-28
 */
@RestController
@RequestMapping("/mes/bom")
public class MesBomController extends BaseController
{
    @Autowired
    private MesBomServiceImpl mesBomService;

    /**
     * 查询生产物品列表
     */
    @PreAuthorize("@ss.hasPermi('mes:bom:list')")
    @GetMapping("/list")
    public TableDataInfo list(MesBom mesBom)
    {
        startPage();
        List<MesBom> list = mesBomService.selectMesBomList(mesBom);
        return getDataTable(list);
    }

    /**
     * 导出生产物品列表
     */
    @PreAuthorize("@ss.hasPermi('mes:bom:export')")
    @Log(title = "生产物品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesBom mesBom)
    {
        List<MesBom> list = mesBomService.selectMesBomList(mesBom);
        ExcelUtil<MesBom> util = new ExcelUtil<MesBom>(MesBom.class);
        util.exportExcel(response, list, "生产物品数据");
    }

    /**
     * 获取生产物品详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:bom:query')")
    @GetMapping(value = "/{goodsCode}")
    public AjaxResult getInfo(@PathVariable("goodsCode") String goodsCode)
    {
        return success(mesBomService.selectMesBomByGoodsCode(goodsCode));
    }

    /**
     * 新增生产物品
     */
    @PreAuthorize("@ss.hasPermi('mes:bom:add')")
    @Log(title = "生产物品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesBom mesBom)
    {
        return toAjax(mesBomService.insertMesBom(mesBom));
    }

    /**
     * 修改生产物品
     */
    @PreAuthorize("@ss.hasPermi('mes:bom:edit')")
    @Log(title = "生产物品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesBom mesBom)
    {
        return toAjax(mesBomService.updateMesBom(mesBom));
    }

    /**
     * 删除生产物品
     */
    @PreAuthorize("@ss.hasPermi('mes:bom:remove')")
    @Log(title = "生产物品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{goodsCodes}")
    public AjaxResult remove(@PathVariable String[] goodsCodes)
    {
        return toAjax(mesBomService.deleteMesBomByGoodsCodes(goodsCodes));
    }
}
